package com.example.controller;

import com.example.common.Result;
import com.example.entity.Admin;
import com.example.entity.Pharmacist;
import com.example.service.AdminService;
import com.example.service.PharmacistService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 药师前端操作接口
 **/

/**
 * @Author: 张比特
 * @Data: 2024/8/28 下午9:33
 * @Version: v1.0.0
 * @Description: TODO
 **/
@RestController
@RequestMapping("/pharmacist")
public class PharmacistController {

    @Resource
    private PharmacistService pharmacistService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public Result add(@RequestBody Pharmacist pharmacist) {
        pharmacistService.add(pharmacist);
        return Result.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        pharmacistService.deleteById(id);
        return Result.success();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public Result updateById(@RequestBody Pharmacist pharmacist) {
        pharmacistService.updateById(pharmacist);
        return Result.success();
    }

    /**
     * 根据ID查询
     */
    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        Pharmacist pharmacist = pharmacistService.selectById(id);
        return Result.success(pharmacist);
    }

    /**
     * 查询所有
     */
    @GetMapping("/selectAll")
    public Result selectAll(Pharmacist pharmacist) {
        List<Pharmacist> list = pharmacistService.selectAll(pharmacist);
        return Result.success(list);
    }

    /**
     * 分页查询
     */
    @GetMapping("/selectPage")
    public Result selectPage(Pharmacist pharmacist,
                             @RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Pharmacist> page = pharmacistService.selectPage(pharmacist, pageNum, pageSize);
        return Result.success(page);
    }

}
